<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>个体商户商品管理系统</title>
    <!-- Favicon icon -->
    <link rel="icon" type="image/png" sizes="16x16" href="./images/favicon.png" />

    <!-- <link href="./css/style.css" rel="stylesheet" /> -->

    <link href="assets/css/lib/font-awesome.min.css" rel="stylesheet">
    <link href="assets/css/lib/themify-icons.css" rel="stylesheet">
    <link href="assets/css/lib/jsgrid/jsgrid-theme.min.css" rel="stylesheet" />
    <link href="assets/css/lib/jsgrid/jsgrid.min.css" type="text/css" rel="stylesheet" />
    <link href="assets/css/lib/menubar/sidebar.css" rel="stylesheet">
    <link href="assets/css/lib/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/lib/helper.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">

    <!-- jquery vendor -->
    <script src="assets/js/lib/jquery.min.js"></script>
    <script src="assets/js/lib/jquery.nanoscroller.min.js"></script>

</head>

<body>

    <script src="./common.js"></script>
    <div class="content-wrap">
        <div class="main">
            <div class="container-fluid">
                <div class="main-content">
                    <div class="row">
                        <div class="col-lg-12 col-sm-12">
                            <div class="card">
                                <div class="stat-widget-two card-body">
                                    <div class="stat-content">
                                        <h4 class="card-title">库存商品总价</h4>
                                        <div class="stat-digit" id="storageValue"><i class="fa fa-cny"></i>storageValue
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-4">
                            <div class="card">
                                <div class="card-header">
                                    <h4 class="card-title">库存商品总数</h4>
                                </div>
                                <div class="card-body">
                                    <h3 class="mt-3" id="storageSumNum">storageSumNum</h3>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-4">
                            <div class="card">
                                <div class="card-header">
                                    <h4 class="card-title">仓库数量</h4>
                                </div>
                                <div class="card-body">
                                    <h3 class="mt-3" id="warehouseNum">warehouseNum</h3>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-4">
                            <div class="card">
                                <div class="card-header">
                                    <h4 class="card-title">店铺数量</h4>
                                </div>
                                <div class="card-body">
                                    <h3 class="mt-3" id="shopNum">shopNum</h3>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="card">
                                <div class="card-header">
                                    <h4 class="card-title text-danger">告警信息</h4>
                                </div>
                                <br>
                                <div class="card-body">
                                    <div class="jsgrid-table-panel">
                                        <div id="jsGrid"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="card">
                                <div class="card-header">
                                    <h4 class="card-title text-danger">待办事项</h4>
                                </div>
                                <br>
                                <div class="card-body">
                                    <div class="jsgrid-table-panel">
                                        <div id="jsGrid_job"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- format Time -->
    <script src="./formatTime.js"></script>

    <!-- make job Detail Readable -->
    <script src="./jobDetailReadable.js"></script>

    <!-- nano scroller -->
    <script src="assets/js/lib/menubar/sidebar.js"></script>
    <script src="assets/js/lib/preloader/pace.min.js"></script>
    <!-- sidebar -->

    <!-- <script src="./js/dashboard/dashboard-1.js"></script> -->

    <!-- JS Grid Scripts Start-->
    <script>
        $(document).ready(function () {
            var db = {
                loadData: function (filter) {
                    return window.db.clients;
                },
                insertItem: function (insertingClient) {
                    window.db.clients.push(insertingClient);
                },
                updateItem: function (updatingClient) { },
                deleteItem: function (deletingClient) {
                    var clientIndex = $.inArray(deletingClient, window.db.clients);
                    window.db.clients.splice(clientIndex, 1);
                }
            };
            window.db = db;
            db.clients = [
            ];
        });
    </script>
    <script src="assets/js/lib/jsgrid/jsgrid.core.js"></script>
    <script src="assets/js/lib/jsgrid/jsgrid.load-indicator.js"></script>
    <script src="assets/js/lib/jsgrid/jsgrid.load-strategies.js"></script>
    <script src="assets/js/lib/jsgrid/jsgrid.sort-strategies.js"></script>
    <script src="assets/js/lib/jsgrid/jsgrid.field.js"></script>
    <script src="assets/js/lib/jsgrid/fields/jsgrid.field.text.js"></script>
    <script src="assets/js/lib/jsgrid/fields/jsgrid.field.number.js"></script>
    <script src="assets/js/lib/jsgrid/fields/jsgrid.field.select.js"></script>
    <script src="assets/js/lib/jsgrid/fields/jsgrid.field.checkbox.js"></script>
    <script src="assets/js/lib/jsgrid/fields/jsgrid.field.control.js"></script>
    <script>
        $(function () {
            $("#jsGrid").jsGrid({
                height: "100%",
                width: "100%",
                filtering: false,
                editing: false,
                inserting: false,
                sorting: true,
                paging: true,
                autoload: true,
                pageSize: 15,
                pageButtonCount: 4,
                deleteConfirm: "真的要删除吗？",
                controller: db,
                noDataContent: "没有警报，好耶!",
                fields: [
                    { name: "alertTitle", title: "告警标题", type: "text", width: 100 },
                    { name: "alertDetail", title: "告警详情", type: "text", width: 220 },
                    { name: "alertTimeReadable", title: "告警时间", type: "text", width: 50 },
                    { type: "control" }
                ],
                rowClick: function (selectRow) {
                    var selectRowData = selectRow.item;
                    var confirmResult = confirm("确定要移除这条告警吗?")
                    if (confirmResult) {
                        var requestObj = {};
                        requestObj["requestService"] = "AlertService";
                        requestObj["requestMethod"] = "deleteAlert";
                        var data = {};
                        data["serialNo"] = selectRowData.serialNo;
                        requestObj["data"] = data;
                        var requestJson = JSON.stringify(requestObj);
                        $.ajax({
                            type: "POST",
                            url: "http://192.168.70.135:80/api/",
                            async: false,
                            contentType: "application/json",
                            data: requestJson,
                            success: function (msg) {
                                location.reload();
                            }
                        });
                    }
                }
            });
        });
    </script>
    <!-- JS Grid Scripts End-->

    <script>
        $(document).ready(function () {
            var jobdb = {
                loadData: function (filter) {
                    return window.jobdb.clients;
                },
                insertItem: function (insertingClient) {
                    window.jobdb.clients.push(insertingClient);
                },
                updateItem: function (updatingClient) { },
                deleteItem: function (deletingClient) {
                    var clientIndex = $.inArray(deletingClient, window.jobdb.clients);
                    window.jobdb.clients.splice(clientIndex, 1);
                }
            };
            window.jobdb = jobdb;
            jobdb.clients = [
            ];
        });
    </script>
    <script>
        $(function () {
            $("#jsGrid_job").jsGrid({
                height: "100%",
                width: "100%",
                filtering: false,
                editing: false,
                inserting: false,
                sorting: true,
                paging: true,
                autoload: true,
                pageSize: 15,
                pageButtonCount: 4,
                deleteConfirm: "真的要删除吗？",
                controller: jobdb,
                noDataContent: "没有待办的事情，好耶!",
                fields: [
                    { name: "jobTitle", title: "任务标题", type: "text", width: 100 },
                    { name: "jobDescribe", title: "任务描述", type: "text", width: 220 }
                ],
                rowClick: function (selectRow) {
                    var selectRowData = selectRow.item;
                    var confirmResult = confirm("确定已经完成了 " + selectRowData.jobTitle + " 这项任务吗?")
                    if (confirmResult) {
                        var requestObj = {};
                        requestObj["requestService"] = "JobService";
                        requestObj["requestMethod"] = "completeJob";
                        var data = {};
                        data["userID"] = window.nowUserInfo.userID;
                        data["serialNo"] = selectRowData.serialNo;
                        requestObj["data"] = data;
                        var requestJson = JSON.stringify(requestObj);
                        $.ajax({
                            type: "POST",
                            url: "http://192.168.70.135:80/api/",
                            async: false,
                            contentType: "application/json",
                            data: requestJson,
                            success: function (msg) {
                                alert("任务执行成功!");
                                location.reload();
                            }
                        });
                    }
                }
            });
        });
    </script>

    <script>
        //加载页面时获取统计数据
        $(document).ready(function () {
            var requestObj = {};
            requestObj["requestService"] = "GetIndexInfoService";
            requestObj["requestMethod"] = "";
            requestObj["data"] = {};
            var requestJson = JSON.stringify(requestObj);
            $.ajax({
                type: "POST",
                url: "http://192.168.70.135:80/api/",
                async: false,
                contentType: "application/json",
                data: requestJson,
                success: function (msg) {
                    $.each(msg.data, function (k, v) {
                        if (k == "storageValue")
                            $("#" + k).html("<i class=\"fa fa-cny\"></i>" + v);
                        else
                            $("#" + k).text(v);
                    });
                },
                error: function (msg) {
                    $("#storageValue").text("无权查看");
                    $("#storageSumNum").text("无权查看");
                    $("#warehouseNum").text("无权查看");
                    $("#shopNum").text("无权查看");
                }
            });
        })
    </script>

    <script>
        //加载页面时获取告警数据
        $(document).ready(function () {
            var requestObj = {};
            requestObj["requestService"] = "AlertService";
            requestObj["requestMethod"] = "selectAllAlert";
            requestObj["data"] = {};
            var requestJson = JSON.stringify(requestObj);
            $.ajax({
                type: "POST",
                url: "http://192.168.70.135:80/api/",
                async: false,
                contentType: "application/json",
                data: requestJson,
                success: function (msg) {
                    window.db.clients = msg.data;
                    $.each(window.db.clients, function (k, v) {
                        var alertTime = v.alertTime;
                        v.alertTimeReadable = formatTime(alertTime / 1000, 'Y/M/D h:m:s');
                    });
                    $("#jsGrid").jsGrid("loadData");
                }
            });
        })
    </script>

    <script>
        //加载页面时获取任务数据
        $(document).ready(function () {
            $(document).ready(function () {
                var requestObj = {};
                requestObj["requestService"] = "JobService";
                requestObj["requestMethod"] = "queryJobList";
                var data = {};
                data["userID"] = window.nowUserInfo.userID;
                requestObj["data"] = data;
                var requestJson = JSON.stringify(requestObj);
                $.ajax({
                    type: "POST",
                    url: "http://192.168.70.135:80/api/",
                    async: false,
                    contentType: "application/json",
                    data: requestJson,
                    success: function (msg) {
                        window.jobdb.clients = msg.data;
                        $.each(window.jobdb.clients, function (k, v) {
                            //将jobDeta进行可读化
                            var result = jobDetailReadable(v.jobDetail);
                            v.jobTitle = result.jobTitle;
                            v.jobDescribe = result.describe;
                        });
                        $("#jsGrid_job").jsGrid("loadData");
                    }
                });
            });
        })
    </script>

</body>

</html>